package csel.view;


import java.util.HashMap;
import csel.model.*;


/*
 * Reasons for Existence: Allows the coupling of Representations and objects within the Model without 
 * forcing them to unnecessarily know one another directly. Encapsulates the conversion of model 
 * representations to visual ones.
 * 
 * @author Alex
 */

public class RepresentationFactory {

	private static RepresentationFactory instance;

	private final HashMap<GameObject,ObjectRepresentor> repSet;
	private final ObjectRepresentor emptyRep;

	public static RepresentationFactory getInstance()
	{
		if (instance == null)
			instance = new RepresentationFactory();
		return instance;
	}

	private RepresentationFactory()
	{
		repSet = new HashMap<GameObject,ObjectRepresentor>();
		emptyRep = new ObjectRepresentor(null);
	}

	public ObjectRepresentor get(GameObject gameObject)
	{
		if (gameObject == null)
			return emptyRep;

		ObjectRepresentor o = repSet.get(gameObject);

		//if there is not yet an ObjectRepresentor for that Object, adds one.
		if (o == null)
		{
			repSet.put(gameObject, new ObjectRepresentor(gameObject));
			o = repSet.get(gameObject);
		}
		return o;       
	}


	
}
